home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / programmers / misc / asmkurs / fpu_julia30.s < prev    next >
Text File  |  1978-06-29  |  8KB  |  298 lines

  1. *
  2. *
  3. *  A simple Julia routine for FPU
  4. *  © 1993 Erik H. Bakke/Bakke SoftDev
  5. *  Some auxillary code by PC PAY/Digital Surface
  6. *
  7. *
  8. *  This routine is intended as illustration only.
  9. *  If you use it in your own programs, give us credit
  10. *  for it, and let us know.  (We like to keep track of how
  11. *  our sources spread)
  12. *
  13. *
  14. *  The Julia subroutine is © 1993 Erik H. Bakke/Bakke SoftDev
  15. *  The system interface is © 1993 PC PAY/Digital Surface
  16. *
  17. *
  18. *  OK, I know that this code could be more elegant, but I don't
  19. *  have the time to do anything about it right now...  (So they all
  20. *  say)
  21. *
  22. *
  23.  
  24.  
  25.  
  26.     include    "startup.i"            ;startup code for Workbench
  27.  
  28.     include    "libraries/exec_lib.i"        ;Exec library _LVO's
  29.     include    "libraries/intuition_lib.i"    ;Intution...
  30.     include    "libraries/graphics_lib.i"    ;Graphics...
  31.  
  32.     include    "intuition/intuition.i"        ;Intuition related stuff
  33.     include    "intuition/screens.i"        ;Intuition screen stuff
  34.     
  35. Width=704                    ;Width of fractal
  36. Height=1128                    ;Height of fractal
  37. Depth=8                        ;Bitplanes used for display
  38. Colors=256                    ;Colors used for display
  39. DisplayID=DBLPALHIRESLACE_KEY            ;Screenmode used for display
  40.  
  41. Init:    move.l    $4.w,a6                ;Get execbase
  42.  
  43.     moveq    #36,d0                ;Library version we want
  44.     lea    (GfxName,pc),a1            ;Name of library
  45.     jsr    (_LVOOpenLibrary,a6)        ;Open library
  46.     move.l    d0,GfxBase            ;Save library base
  47.     beq.w    GfxError            ;Exit if error
  48.  
  49.     moveq    #36,d0
  50.     lea    (IntName,pc),a1
  51.     jsr    (_LVOOpenLibrary,a6)
  52.     move.l    d0,a6
  53.     move.l    d0,IntBase
  54.     beq.w    IntError
  55.  
  56.     lea    $0.w,a0                ;Newscreen structure
  57.     lea    (ScrAttrs,pc),a1        ;Taglist for screen
  58.     jsr    (_LVOOpenScreenTagList,a6)    ;Open screen
  59.     move.l    d0,Scr                ;Save pointer
  60.     beq.w    ScrError            ;Exit if error
  61.     
  62.     lea    $0.w,a0                ;Newwindow structure
  63.     lea    (WinAttrs,pc),a1        ;Taglist for window
  64.     jsr    (_LVOOpenWindowTagList,a6)    ;Open window
  65.     move.l    d0,Win                ;Save pointer
  66.     beq.w    WinError            ;Exit if error
  67.  
  68.     move.l    d0,a0                ;Get window pointer
  69.     move.l    (wd_RPort,a0),a5        ;Get rastport pointer
  70.     move.l    (GfxBase,pc),a6            ;Get graphics base
  71.  
  72.     move.l    (Scr,pc),a0            ;Get screen pointer
  73.     add.l    #sc_ViewPort,a0            ;Get viewport pointer
  74.     lea    (Cols,pc),a1            ;Colormap
  75.     move.l    #Colors,d0            ;Number of colors
  76.     jsr    (_LVOLoadRGB4,a6)        ;Set palette
  77.  
  78.     fmove.w    #270,fp0                ;Find a good seed value
  79.     fmove.x    fp0,fp1
  80.  
  81.     fmovecr.x    #0,fp2                ;Calculate radians for
  82.     fdiv.w    #180,fp2            ;the trigonometric that
  83.     fadd.x    fp2,fp2                ;follows
  84.     fmul.x    fp2,fp0
  85.     fmul.x    fp2,fp1
  86.  
  87.  
  88.     fsin.x    fp0                ;Get a good starting spot
  89.     fcos.x    fp1
  90.     fdiv.w    #300,fp0
  91.     fdiv.w    #300,fp1
  92.     fmul.w    #190,fp0
  93.     fmul.w    #190,fp1
  94.     fmove.x    fp0,q
  95.     fmove.x    fp1,p
  96.     bsr    Julia                ;Draw julia fractal
  97.  
  98. m:    btst    #$2,$dff016            ;Wait for right mouse button
  99.     bne    m
  100.  
  101.     move.l    (IntBase,pc),a6            ;Get intuition base
  102.     move.l    (Win,pc),a0            ;Get window pointer
  103.     jsr    (_LVOCloseWindow,a6)        ;Close window
  104. WinError:
  105.     move.l    (Scr,pc),a0            ;Get screen pointer
  106.     jsr    (_LVOCloseScreen,a6)        ;Close screen
  107. ScrError:
  108.     move.l    a6,a1                ;Get library pointer
  109.     move.l    $4.w,a6                ;Get execbase
  110.     jsr    (_LVOCloseLibrary,a6)        ;Close library
  111. IntError:
  112.     move.l    (GfxBase,pc),a1            ;Get library pointer
  113.     jsr    (_LVOCloseLibrary,a6)        ;Close library
  114. GfxError:
  115.     rts                    ;Exit
  116.  
  117.  
  118.  
  119. Julia:    fmove.l    #10000000,fp7            ;Provide some decimal places
  120.     fmove.l    #12000000,fp0                ;xmax=1.2
  121.     fdiv.x    fp7,fp0
  122.     fmove.l    #-12000000,fp1            ;xmin=-1.2
  123.     fdiv.x    fp7,fp1
  124.     fmove.l    #12000000,fp2            ;ymax=1.2
  125.     fdiv.x    fp7,fp2
  126.     fmove.l    #-12000000,fp3            ;ymin=-1.2
  127.     fdiv.x    fp7,fp3
  128.  
  129.     fmove.x    (q,pc),fp5            ;Get q and p
  130.     fmove.x    (p,pc),fp4
  131.  
  132.     move.l    #Width,d0
  133.     move.l    #Height,d1
  134.     fmove.x    fp2,ymax            ;Save ymax
  135.     fsub.x    fp1,fp0                ;get horizontal steprate
  136.     fdiv.l    d0,fp0                ; dx=(xmax-xmin)/width
  137.     fsub.x    fp3,fp2                ;get vertical steprate
  138.     fdiv.l    d1,fp2                ; dy=(ymax-ymin)/height
  139.  
  140.     fmove.x    fp5,fp3                ;Get q
  141.     
  142.     fmove.x    fp0,xdelta            ;save deltas
  143.     fmove.x    fp2,ydelta
  144.     
  145.     move.w    #Height/2,d4            ;Preload this one...
  146.  
  147.     moveq    #-$1,d7                ;
  148. .nextx    addq.w    #$1,d7                ;
  149.     cmp.w    #Width/2+1,d7            ; for x=0 to 321
  150.     beq.w    .exit
  151.     moveq    #-$1,d6                ;
  152. .nexty    addq.w    #$1,d6                ;
  153.     cmp.w    #Height,d6            ; for y=0 to 256
  154.     beq.b    .nextx
  155.     
  156.     fmove.w    d7,fp7                ;
  157.     fmul.x    (xdelta,pc),fp7            ; x=xc*dx+xmin
  158.     fmove.w    d6,fp6                ;
  159.     fmul.x    (ydelta,pc),fp6            ;
  160.     fadd.x    fp1,fp7                ; y=ymax-yc*dy
  161.     fmove.x    (ymax,pc),fp0            ;
  162.     fsub.x    fp6,fp0
  163.  
  164.     fmove.w    #$0,fp6                ;x²=0
  165.     fmove.x    fp6,fp5                ;y²=0
  166.  
  167.     move.w    #255,d5                ;256 iterations
  168.     moveq    #$4,d3                ;preload this one too...
  169.  
  170. .iter
  171.     fmove.x    fp6,fp2                ;
  172.     fadd.x    fp5,fp2                ;if (x²+y²>4) then
  173.     fcmp.w    d3,fp2
  174.     fbgt.w    .growed
  175.     fmove.x    fp7,fp6                ;
  176.     fmul.x    fp6,fp6                ;x²=x*x
  177.     fmove.x    fp0,fp5                ;
  178.     fmul.x    fp7,fp0                ;y=2x*y+p
  179.     fmul.x    fp5,fp5                ;
  180.     fadd.x    fp0,fp0                ;
  181.     fadd.x    fp4,fp0                ;
  182.     fmove.x    fp6,fp7                ;x=x+q-y
  183.     fadd.x    fp3,fp7                ;
  184.     fsub.x    fp5,fp7            
  185.     dbf    d5,.iter
  186.  
  187. .growed
  188.     move.w    d6,d1                ;get x 
  189.     move.w    d7,d0                ;get y
  190.     neg.w    d5
  191.     add.w    #256,d5
  192.     move.w    d5,d2                ;get color
  193.     ext.l    d2                ;remove unwanted data
  194.     bsr.w    PlotPoint            ;Plot this point
  195.     move.w    d6,d1                ;get x
  196.     move.w    d7,d0                ;get y
  197.     sub.w    #Width/2,d0            ;
  198.     neg.w    d0                ;the julia fractal is symmetrical
  199.     add.w    #Width/2,d0            ;
  200.     
  201.     sub.w    d4,d1                ;
  202.     neg.w    d1                ;
  203.     add.w    d4,d1                ;
  204.     
  205.     move.w    d5,d2                ;get color
  206.     ext.l    d2                ;remove unwanted data
  207.     bsr.w    PlotPoint            ;Plot this point
  208.     btst    #$2,$dff016
  209.     beq    .exit
  210.     bra.w    .nexty                ;loop y-count
  211.  
  212. .exit    rts                    ;exit
  213.  
  214. ymax:    dc.x    0                ;some variables
  215. xdelta:    dc.x    0
  216. ydelta:    dc.x    0
  217. x:    dc.x    0
  218. y:    dc.x    0
  219. q:    dc.x    0
  220. p:    dc.x    0
  221.  
  222. *
  223. * d0=x d1=y d2=c
  224. *
  225.  
  226. PlotPoint:
  227.     movem.l    d0-d1,-(sp)            ;store important registers
  228.     move.l    (GfxBase,pc),a6            ;get graphics library
  229.     move.l    a5,a1                ;Get rastport
  230.     move.l    d2,d0                ;Get color
  231.     jsr    (_LVOSetAPen,a6)        ;Set pen color
  232.     movem.l    (sp)+,d0-d1            ;restore important registers
  233.     move.l    a5,a1                ;Get rastport
  234.     jsr    (_LVOWritePixel,a6)        ;Write pixel
  235.     rts                    ;Return
  236. *-----------------------------------------------------------------------------
  237. ScrAttrs:                    ;Taglist for screen
  238.     dc.l    SA_Width,Width            ;Screen width
  239.     dc.l    SA_Height,Height        ;Screen height
  240.     dc.l    SA_Depth,Depth            ;Screen depth
  241.     dc.l    SA_Type,CUSTOMSCREEN        ;Screen type
  242.     dc.l    SA_DisplayID,DisplayID        ;Screen display mode
  243.     dc.l    TAG_END,0            ;End of taglist
  244. *-----------------------------------------------------------------------------
  245. WinAttrs:
  246.     dc.l    WA_Width,Width            ;Window width
  247.     dc.l    WA_Height,Height        ;Window height
  248.     dc.l    WA_Flags,WFLG_BORDERLESS    ;Window flags
  249.     dc.l    WA_CustomScreen            ;Window screen pointer
  250. Scr:    dc.l    0
  251.     dc.l    TAG_END,0            ;End of taglist
  252. *-----------------------------------------------------------------------------
  253. Cols:    dc.w    $000,$111,$222,$333,$444,$555,$666,$777    ;colormap
  254.     dc.w    $888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff
  255.     dc.w    $ffe,$ffd,$ffc,$ffb,$ffa,$ff9,$ff8,$ff7
  256.     dc.w    $ff6,$ff5,$ff4,$ff3,$ff2,$ff1,$ff0,$fe0
  257.  
  258.     dc.w    $fd0,$fc0,$fb0,$fa0,$f90,$f80,$f70,$f60
  259.     dc.w    $f50,$f40,$f30,$f20,$f10,$f00,$f01,$f02
  260.     dc.w    $f03,$f04,$f05,$f06,$f07,$f08,$f09,$f0a
  261.     dc.w    $f0b,$f0d,$f0e,$f0f,$e0f,$d0f,$c0f,$b0f
  262.  
  263.     dc.w    $a0f,$90f,$80f,$70f,$60f,$50f,$40f,$30f
  264.     dc.w    $20f,$10f,$00f,$01f,$02f,$03f,$04f,$05f
  265.     dc.w    $06f,$07f,$08f,$09f,$0af,$0bf,$0cf,$0df
  266.     dc.w    $0ef,$0ff,$1ef,$2df,$3cf,$4bf,$5af,$69f
  267.  
  268.     dc.w    $78f,$87f,$96f,$a5f,$b4f,$c3f,$d2f,$e1f
  269.     dc.w    $f0f,$f1f,$f2f,$f3f,$f4f,$f5f,$f6f,$f7f
  270.     dc.w    $f8f,$f9f,$faf,$fbf,$fcf,$fdf,$fef,$fff
  271.     dc.w    $eef,$ddf,$ccf,$bbf,$aaf,$99f,$88f,$77f
  272.  
  273.     dc.w    $66f,$55f,$44f,$33f,$22f,$11f,$00f,$01e
  274.     dc.w    $888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff
  275.     dc.w    $ffe,$ffd,$ffc,$ffb,$ffa,$ff9,$ff8,$ff7
  276.     dc.w    $ff6,$ff5,$ff4,$ff3,$ff2,$ff1,$ff0,$fe0
  277.  
  278.     dc.w    $000,$111,$222,$333,$444,$555,$666,$777    ;The last 3 blocks
  279.     dc.w    $888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff ;are repetition...
  280.     dc.w    $ffe,$ffd,$ffc,$ffb,$ffa,$ff9,$ff8,$ff7
  281.     dc.w    $ff6,$ff5,$ff4,$ff3,$ff2,$ff1,$ff0,$fe0
  282.  
  283.     dc.w    $000,$111,$222,$333,$444,$555,$666,$777
  284.     dc.w    $888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff
  285.     dc.w    $ffe,$ffd,$ffc,$ffb,$ffa,$ff9,$ff8,$ff7
  286.     dc.w    $ff6,$ff5,$ff4,$ff3,$ff2,$ff1,$ff0,$fe0
  287.  
  288.     dc.w    $000,$111,$222,$333,$444,$555,$666,$777
  289.     dc.w    $888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff
  290.     dc.w    $ffe,$ffd,$ffc,$ffb,$ffa,$ff9,$ff8,$ff7
  291.     dc.w    $ff6,$ff5,$ff4,$ff3,$ff2,$ff1,$ff0,$000
  292. *-----------------------------------------------------------------------------
  293. Win:        dc.l    0            ;Window pointer
  294. IntBase:    dc.l    0            ;Intuition library pointer
  295. GfxBase:    dc.l    0            ;Graphics library pointer
  296. IntName:    dc.b    "intuition.library",0
  297. GfxName:    dc.b    "graphics.library",0
  298.